<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录 - AI简历分析系统</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css" rel="stylesheet">
    <style>
        /* CSS 变量用于统一颜色方案 */
        :root {
            --primary-color: #5A67D8; /* 更柔和的主色调 */
            --primary-hover: #434B9A;
            --text-color: #2D3748;
            --light-gray: #F7FAFC;
            --border-color: #E2E8F0;
            --error-color: #E53E3E;
        }

        body {
            font-family: 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
            background-color: var(--light-gray);
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            margin: 0;
            color: var(--text-color);
        }

        .container {
            background-color: white;
            padding: 3rem; /* 增加内边距 */
            border-radius: 12px;
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08);
            width: 100%;
            max-width: 400px;
            text-align: center;
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }

        .container:hover {
            transform: translateY(-5px);
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
        }

        h2 {
            margin: 0 0 2rem 0; /* 增加标题底部间距 */
            color: var(--text-color);
            font-weight: 600;
        }

        .form-group {
            margin-bottom: 2rem; /* 增加表单组间距 */
            text-align: left;
            position: relative;
        }

        .form-control {
            border: 1px solid var(--border-color);
            border-radius: 8px;
            padding: 0.75rem 1rem;
            width: 100%;
            transition: border-color 0.3s ease, box-shadow 0.3s ease;
        }

        .form-control:focus {
            border-color: var(--primary-color);
            outline: none;
            box-shadow: 0 0 0 3px rgba(90, 103, 216, 0.2);
        }

        button {
            width: 100%;
            padding: 0.75rem;
            border: none;
            border-radius: 8px;
            background-color: var(--primary-color);
            color: white;
            font-size: 1rem;
            font-weight: 600;
            cursor: pointer;
            transition: background-color 0.3s ease, transform 0.2s ease;
        }

        button:hover {
            background-color: var(--primary-hover);
            transform: translateY(-2px);
        }

        .link-container {
            margin-top: 1.5rem;
        }

        .link {
            color: var(--primary-color);
            text-decoration: none;
            font-size: 0.9rem;
            transition: color 0.3s ease;
        }

        .link:hover {
            color: var(--primary-hover);
            text-decoration: underline;
        }

        .error-message {
            color: var(--error-color);
            font-size: 0.85rem;
            margin-top: 0.5rem;
            text-align: center;
        }

        /* 专门用于登录页面的样式 */
        .password-error {
            color: var(--error-color);
            font-size: 0.85rem;
            margin-top: 0.5rem;
            display: none;
        }

        .form-group.error .password-error {
            display: block;
        }
    </style>
</head>
<body>
<div class="container">
    <h2 class="text-center">登录</h2>
    <div th:if="${param.error}" class="alert alert-danger error-message" role="alert">
        无效的用户名或密码
    </div>
    <form id="loginForm" th:action="@{/login}" method="post">
        <div class="form-group">
            <label for="username">用户名</label>
            <input type="text" class="form-control" id="username" name="username"
                   placeholder="请输入用户名" required
                   th:value="${username}">
        </div>

        <div class="form-group" th:classappend="${passwordError} ? 'error' : ''">
            <label for="password">密码</label>
            <input type="password" class="form-control" id="password" name="password"
                   placeholder="请输入密码" required>
            <div class="password-error" th:if="${passwordError}">密码错误，请重新输入</div>
        </div>

        <input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}" />
        <button type="submit">登录</button>
    </form>

    <div class="link-container">
        <a class="link" th:href="@{/register}">还没有账号？立即注册</a>
    </div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
    document.addEventListener('DOMContentLoaded', function() {
        const passwordInput = document.getElementById('password');
        const passwordGroup = passwordInput.closest('.form-group');

        if (passwordGroup.querySelector('.password-error')) {
            passwordGroup.classList.add('error');
        }

        passwordInput.addEventListener('input', function() {
            passwordGroup.classList.remove('error');
        });
    });
</script>
</body>
</html>